use std::fmt::{Debug, Error, Formatter};

/// 抽象语法树节点
/// 在Rust中树和链表之类的数据结构通常用enum来实现
pub enum AstNode {
    TopStatementList(Vec<AstNode>),
    Echo(Vec<AstNode>),
    LineComment(String),
    MultLinesComment(String),
    Int(i64),
    String(String),
}

impl Debug for AstNode {
    fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
        use self::AstNode::*;
        match *self {
            TopStatementList(ref v) => write!(fmt, "{:?}", v),
            Echo(ref v) => write!(fmt, "echo {:?}", v),
            LineComment(ref s) => write!(fmt, "行注释 - {:?}", s),
            MultLinesComment(ref s) => write!(fmt, "多行注释 - {:?}", s),
            Int(n) => write!(fmt, "{}", n),
            String(ref s) => write!(fmt, "{}", s),
        }
    }
}

/// 操作码
pub enum Opcode {
    Add,
    Sub,
    Mul,
    Div,
}
